import React from 'react';
import { findDOMNode } from 'react-dom';

const AddUser = React.createClass({
  render() {
    let addUser = this.props.addUser;
    console.log(addUser.toString());
    let _this = this;
    return (
      <div>
        <input type="text" ref="name"/>
        <input type="text" ref="age"/>
        <input type="text" ref="gender"/>
        <button onClick={e => this.handleClick(e)}>添加新用户</button>
      </div>
    );
  },
  handleClick(e) {
    const nameNode = this.refs.name;
    //const nameNode = findDOMNode(this.refs.name);
    const ageNode = this.refs.age;
    const genderNode = this.refs.gender;
    const name = nameNode.value.trim();
    const age = ageNode.value.trim();
    const gender = genderNode.value.trim();
    this.props.addUser({
      name: name,
      age: age,
      gender: gender
    });
    nameNode.value = '';
    ageNode.value = '';
    genderNode.value = '';
  }
});

export default AddUser;
